home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_054 / ispell / access.c next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  50 lines

  1. #include <stdio.h>
  2. #include <exec/types.h>      /* For Lattice 3.10, must be before exec.h! */
  3. #include <exec/exec.h>
  4. #include <libraries/dos.h>
  5. #include <libraries/dosextens.h>
  6. #undef TRUE
  7. #undef FALSE
  8.  
  9. #ifdef LATTICE    /* Lattice 3.10 version is hosed, use our own */
  10.  
  11. #include <error.h>
  12.  
  13. int access (path, mode)
  14. char *path;
  15. int mode;
  16. {
  17.     long lck;
  18.     struct FileInfoBlock *fp;
  19.     int rtnval = 0;
  20.     register long prot;
  21.     extern long Lock ();
  22.     extern void *AllocMem ();
  23.  
  24.     if ((path == 0) || ((lck = Lock (path, (long) ACCESS_READ)) == 0)) {
  25.     rtnval = -1;
  26.     errno = ENOENT;
  27.     } else {
  28.     fp = (struct FileInfoBlock *)
  29.         AllocMem ((long) sizeof (struct FileInfoBlock),
  30.         (long) (MEMF_CLEAR | MEMF_CHIP));
  31.     if (Examine (lck, fp) == 0) {
  32.         rtnval = -1;
  33.         errno = EACCES;
  34.     } else {
  35.         prot = fp -> fib_Protection;
  36.         if (  ((mode & 1) && (prot & FIBF_EXECUTE))
  37.            || ((mode & 2) && (prot & FIBF_WRITE))
  38.            || ((mode & 4) && (prot & FIBF_READ))) {
  39.             rtnval = -1;
  40.             errno = EACCES;
  41.         }
  42.     }
  43.     FreeMem (fp, (long) sizeof (struct FileInfoBlock));
  44.     UnLock (lck);
  45.     }
  46.     return (rtnval);
  47. }
  48.  
  49. #endif
  50.